package com.k.util.resourcebundle.xml;

import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Locale;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.Set;

/**
 * 读取xml资源文件
 * @version v1.0.0
 */
public class XMLResourceBundle extends ResourceBundle {

    /**
     * 属性
     */
    private Properties props;
    XMLResourceBundle(InputStream stream) throws IOException {
        props = new Properties();
        props.loadFromXML(stream);
    }
    /**
     * get
     * @param key .
     * @return .
     */
    @Override
    protected Object handleGetObject(String key) {
        return props.getProperty(key);
    }
    /**
     * get
     * @return .
     */
    @Override
    public Enumeration<String> getKeys() {
        Set<String> handleKeys = props.stringPropertyNames();
        return Collections.enumeration(handleKeys);
    }
    /**
     * test
     * @param args .
     */
    public static void main(String[] args) {
        ResourceBundle bundle = ResourceBundle.getBundle("language/Language", new Locale("zh", "CN"),new XMLResourceBundleControl());
        String string = bundle.getString("LOGINING");
        System.out.println("Key: " + string);
        
        ResourceBundle bundle1 = ResourceBundle.getBundle("language/Language", new Locale("en", "US"),new XMLResourceBundleControl());
        String string1 = bundle1.getString("LOGINING");
        System.out.println("Key1: " + string1);
        
    }
}
